package com.qingfeng.testandroid12sdkdemo.fragment

import androidx.lifecycle.MutableLiveData
import com.qingfeng.basic_lib.basic.BasicViewModel
import com.qingfeng.testandroid12sdkdemo.data.entity.BannerBean
import com.qingfeng.testandroid12sdkdemo.data.entity.HomeListBean
import com.qingfeng.testandroid12sdkdemo.utils.InjectorUtil

class HomeViewModel : BasicViewModel() {

    private val homeRepository by lazy { InjectorUtil.getHomeRepository() }

    private val mBanners = MutableLiveData<List<BannerBean>>()

    private val projectData = MutableLiveData<HomeListBean>()

    fun getBanner(refresh: Boolean = false): MutableLiveData<List<BannerBean>> {
        launchGo(
            {
                mBanners.value = homeRepository.getBannerData(refresh)
            }
        )
        return mBanners
    }

    fun getHomeList(page: Int, refresh: Boolean = false): MutableLiveData<HomeListBean> {
        launchGo({
            projectData.value = homeRepository.getHomeList(page, refresh)
        },{
            projectData.value = null
        })
        return projectData
    }

}